package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-11-02
 * Time: 10:59
 */
public class ReturnBook implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您想归还的书籍名字");
        String name = sc.nextLine();

        int currSize = bookList.getUsedSize();
        for (int i = 0; i < currSize; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)){
                if (book.isBorrowed()){
                    System.out.println("归还成功！！！");
                    book.setBorrowed(false);
                    System.out.println(book);
                }
                else {
                    System.out.println("这本书暂未被借出，不用还！");
                }
                return;
            }
        }
        System.out.println("没有你找的这本书，不用归还！！");
    }
}
